<p>在二元运算符的两边使用相同的值，这通常都没意义。它要么是复制/粘贴错了，要么是浪费的代码。</p>
<p>该规则忽略 <code>*</code>, <code>+</code>, 和 <code>=</code>. </p>
<h2>不规范代码示例</h2>

<pre>
if ( a == a ) { // always true
  doZ();
}
if ( a != a ) { // always false
  doY();
}
if ( a == b &amp;&amp; a == b ) { // 如果第一个是正确的，第二个也是
  doX();
}
if ( a == b || a == b ) { // if the first one is true, the second one is too
  doW();
}

int j = 5 / 5; //always 1
int k = 5 - 5; //always 0
</pre>
<h2>正确代码示例</h2>

<pre>
doZ();

if ( a == b ) {
  doX();
}
if ( a == b ) {
  doW();
}

int j = 1;
int k = 0;
</pre>
<h2>例外</h2>

<p>针对其自身测试浮点值的特定情况是对<code> NaN </code>的有效测试，因此将被忽略。</p> <p>类似地，在构造时，通常将1左移到1位掩码，并且被忽略。</p>
<pre>
float f;
if(f != f) { //test for NaN value
  System.out.println("f is NaN");
}

int i = 1 &lt;&lt; 1; // Compliant
int j = a &lt;&lt; a; // Noncompliant
</pre>
<h2>更多</h2>

<ul>
<li> <a href="https://www.securecoding.cert.org/confluence/x/NYA5">CERT, MSC12-C</a> - Detect and remove code that has no effect</li>
<li> <a href="https://www.securecoding.cert.org/confluence/x/SIIyAQ">CERT, MSC12-CPP</a> - Detect and remove code that has no effect</li>
<li> Rule S1656 - Implements a check on <code>=</code>. </li>
</ul>

